package com.acme.bankapp.domain.bank;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import com.acme.bankapp.domain.account.Account;
import com.acme.bankapp.domain.client.Client;
import com.acme.bankapp.domain.client.ClientRegistrationListener;
import com.acme.bankapp.domain.exception.ClientExistsException;

public class Bank implements Serializable{
	
	private Set<Client> clients = new HashSet<>();
	private ClientRegistrationListener[] listeners;
	
	public Bank(){
	}
	
	public Bank(ClientRegistrationListener[] listeners){
		this();
		this.listeners=listeners; 
	}
		
	public void addClient(Client client) throws ClientExistsException {
        if (clients.contains(client))
        	throw new ClientExistsException("Client with name - " + client.getName() + " alredy exsist!");

        clients.add(client);

        for (ClientRegistrationListener listener : listeners) {
                listener.onClientAdded(client);
        }
}
		
	public Set<Client> getClients() {
		return Collections.unmodifiableSet(clients);
	}

	public int getCountClients() {
		return clients.size();
	}
	
	public static class PrintClientListener implements ClientRegistrationListener{
		@Override
		public void onClientAdded(Client c){
			System.out.println(c.getName() + " registered");
		}
	}
	
	public static class EmailNotificationListener implements ClientRegistrationListener{
		@Override
		public void onClientAdded(Client c){
			System.out.println("Notification email for client " + c.getName() + " to be sent");
		}
	}
	
	public static class DebugListener implements ClientRegistrationListener {
         @Override
         public void onClientAdded(Client c) {
        	 System.out.println(c.getName() + " " + new Date());
         }
	}
 
	

}
